package com.guw.AWT;

import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class ExDemo {
    public static void main(String[] args) {
        //总窗口
        Frame frame = new Frame("练习");

        frame.setVisible(true);
        frame.setSize(400,500);
        frame.setLocation(400,200);
        frame.setLayout(new GridLayout(2,1));

        //4个面板
        Panel p1 = new Panel(new BorderLayout());
        Panel p2 = new Panel(new GridLayout(2,1));
        Panel p3 = new Panel(new BorderLayout());
        Panel p4 = new Panel(new GridLayout(2,2));

        //测试失败案例
        /*p1.setBounds(0,0,400,250);
        p2.setBounds(100,0,200,250);
        p3.setBounds(0,250,400,250);
        p4.setBounds(100,250,200,250);*/

        //上半部分
        p1.add(new Button("east-1"),BorderLayout.EAST);
        p1.add(new Button("west-1"),BorderLayout.WEST);
        p2.add(new Button("north-1"));
        p2.add(new Button("south-1"));
        p1.add(p2,BorderLayout.CENTER);

        //下半部分
        p3.add(new Button("east-2"),BorderLayout.EAST);
        p3.add(new Button("west-2"),BorderLayout.WEST);
        p4.add(new Button("1"));
        p4.add(new Button("2"));
        p4.add(new Button("3"));
        p4.add(new Button("4"));
        p3.add(p4,BorderLayout.CENTER);

        frame.add(p1);
        frame.add(p3);

        frame.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });

    }

}
